Dynomotion

Group: DynoMotion Message: 3875 From: himykabibble Date: 2/12/2012
Subject: fprintf bug?
Tom,

This code:

for (j=0; j<n; j++)
fprintf(f, "%16.3f,", p[i+j+1]);

seems to not work quite correctly. The data prints correctly, but each string is followed by a 0x02 character.

Regards,
Ray L.
Group: DynoMotion Message: 3876 From: Tom Kerekes Date: 2/12/2012
Subject: Re: fprintf bug?
Hi Ray,
 
Are you putting in New Line characters?  '\n'
 
There is a limit to a line's lengh of 128 characters.  See:
 
#define
MAX_STRING 128
 
TK

Group: DynoMotion Message: 3877 From: himykabibble Date: 2/12/2012
Subject: Re: fprintf bug?
Tom,

Nowhere near the 128 character limit - I do a newline after a group of four values are printed. It's inserting the bogus character even on the very first fprintf call, which is only outputting about 20 characters.

Regards,
Ray L.

--- In DynoMotion@yahoogroups.com, Tom Kerekes <tk@...> wrote:
>
> Hi Ray,
>  
> Are you putting in New Line characters?  '\n'
>  
> There is a limit to a line's lengh of 128 characters.  See:
>  #define
>  
> TKMAX_STRING 128
>
> From: himykabibble <jagboy@...>
> To: DynoMotion@yahoogroups.com
> Sent: Sunday, February 12, 2012 7:07 PM
> Subject: [DynoMotion] fprintf bug?
>
>
>  
> Tom,
>
> This code:
>
> for (j=0; j<n; j++)
> fprintf(f, "%16.3f,", p[i+j+1]);
>
> seems to not work quite correctly. The data prints correctly, but each string is followed by a 0x02 character.
>
> Regards,
> Ray L.
>
Group: DynoMotion Message: 3878 From: Tom Kerekes Date: 2/12/2012
Subject: Re: fprintf bug?
Ray,
 
Are you trying to printf to the Console or fprintf to a File?
 
TK

Group: DynoMotion Message: 3879 From: himykabibble Date: 2/12/2012
Subject: Re: fprintf bug?
Tom,

A file. Here's the whole function - all works except for the extra characters.

void WriteCapture(char* filepath, int n)
{
int i, j;
p = gather_buffer;

FILE *f = fopen(filepath, "wt");
for (i=0; i<MAX_CAPTURE; i+=(n+1))
{
p[0] = ((int)(p[0]/TIMEBASE + 0.5))*TIMEBASE;
fprintf(f, ",%16.9f,", p[i]);
for (j=0; j<n; j++)
fprintf(f, ",%16.3f,", p[i+j+1]);
fprintf(f, "\n");
}
fclose(f);
}

Regards,
Ray L.

--- In DynoMotion@yahoogroups.com, Tom Kerekes <tk@...> wrote:
>
> Ray,
>  
> Are you trying to printf to the Console or fprintf to a File?
>  
> TK
>
> From: himykabibble <jagboy@...>
> To: DynoMotion@yahoogroups.com
> Sent: Sunday, February 12, 2012 7:27 PM
> Subject: [DynoMotion] Re: fprintf bug?
>
>
>  
> Tom,
>
> Nowhere near the 128 character limit - I do a newline after a group of four values are printed. It's inserting the bogus character even on the very first fprintf call, which is only outputting about 20 characters.
>
> Regards,
> Ray L.
>
> --- In DynoMotion@yahoogroups.com, Tom Kerekes <tk@> wrote:
> >
> > Hi Ray,
> >  
> > Are you putting in New Line characters?  '\n'
> >  
> > There is a limit to a line's lengh of 128 characters.  See:
> >  #define
> >  
> > TKMAX_STRING 128
> >
> > From: himykabibble <jagboy@>
> > To: DynoMotion@yahoogroups.com
> > Sent: Sunday, February 12, 2012 7:07 PM
> > Subject: [DynoMotion] fprintf bug?
> >
> >
> >  
> > Tom,
> >
> > This code:
> >
> > for (j=0; j<n; j++)
> > fprintf(f, "%16.3f,", p[i+j+1]);
> >
> > seems to not work quite correctly. The data prints correctly, but each string is followed by a 0x02 character.
> >
> > Regards,
> > Ray L.
> >
>
Group: DynoMotion Message: 3880 From: Tom Kerekes Date: 2/12/2012
Subject: Re: fprintf bug?
Hi Ray,
 
Hmmmm   I don't think KMotionServer is expecting to have a line sent piecemeal like that.  I suppose it is technically correct but not very efficient as it will be sending more USB packets per line.
 
Try building one complete string and fprintf the entire string at once.
 
Or actually it might just not handle that one packet with only a New Line character.  Maybe add a space before the \n and see if that works.
 
Regards
TK

Group: DynoMotion Message: 3881 From: himykabibble Date: 2/12/2012
Subject: Re: fprintf bug?
Tom,

*Each* fprintf has the 0x02 appended to the string, so adding a space before the new line won't change anything. I realize I could just sprintf the string, then send it with a single fprintf, just thought it was odd that this didn't work right.

Regards,
Ray L.

--- In DynoMotion@yahoogroups.com, Tom Kerekes <tk@...> wrote:
>
> Hi Ray,
>  
> Hmmmm   I don't think KMotionServer is expecting to have a line sent piecemeal like that.  I suppose it is technically correct but not very efficient as it will be sending more USB packets per line.
>  
> Try building one complete string and fprintf the entire string at once.
>  
> Or actually it might just not handle that one packet with only a New Line character.  Maybe add a space before the \n and see if that works.
>  
> Regards
> TK
>
> From: himykabibble <jagboy@...>
> To: DynoMotion@yahoogroups.com
> Sent: Sunday, February 12, 2012 8:32 PM
> Subject: [DynoMotion] Re: fprintf bug?
>
>
>  
> Tom,
>
> A file. Here's the whole function - all works except for the extra characters.
>
> void WriteCapture(char* filepath, int n)
> {
> int i, j;
> p = gather_buffer;
>
> FILE *f = fopen(filepath, "wt");
> for (i=0; i<MAX_CAPTURE; i+=(n+1))
> {
> p[0] = ((int)(p[0]/TIMEBASE + 0.5))*TIMEBASE;
> fprintf(f, ",%16.9f,", p[i]);
> for (j=0; j<n; j++)
> fprintf(f, ",%16.3f,", p[i+j+1]);
> fprintf(f, "\n");
> }
> fclose(f);
> }
>
> Regards,
> Ray L.
>
> --- In DynoMotion@yahoogroups.com, Tom Kerekes <tk@> wrote:
> >
> > Ray,
> >  
> > Are you trying to printf to the Console or fprintf to a File?
> >  
> > TK
> >
> > From: himykabibble <jagboy@>
> > To: DynoMotion@yahoogroups.com
> > Sent: Sunday, February 12, 2012 7:27 PM
> > Subject: [DynoMotion] Re: fprintf bug?
> >
> >
> >  
> > Tom,
> >
> > Nowhere near the 128 character limit - I do a newline after a group of four values are printed. It's inserting the bogus character even on the very first fprintf call, which is only outputting about 20 characters.
> >
> > Regards,
> > Ray L.
> >
> > --- In DynoMotion@yahoogroups.com, Tom Kerekes <tk@> wrote:
> > >
> > > Hi Ray,
> > >  
> > > Are you putting in New Line characters?  '\n'
> > >  
> > > There is a limit to a line's lengh of 128 characters.  See:
> > >  #define
> > >  
> > > TKMAX_STRING 128
> > >
> > > From: himykabibble <jagboy@>
> > > To: DynoMotion@yahoogroups.com
> > > Sent: Sunday, February 12, 2012 7:07 PM
> > > Subject: [DynoMotion] fprintf bug?
> > >
> > >
> > >  
> > > Tom,
> > >
> > > This code:
> > >
> > > for (j=0; j<n; j++)
> > > fprintf(f, "%16.3f,", p[i+j+1]);
> > >
> > > seems to not work quite correctly. The data prints correctly, but each string is followed by a 0x02 character.
> > >
> > > Regards,
> > > Ray L.
> > >
> >
>